package com.yy.job.jobhandler;

import com.xxl.job.core.handler.annotation.XxlJob;
import com.yy.device.api.TaskApi;
import com.yy.device.boot.DeviceDataContainer;
import com.yy.device.enums.DeviceDataEnum;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 剩余污泥排放电磁阀
 *
 * @author zhiqiang.sun
 * @date 2022/06/30
 */
@Component
@Slf4j
public class _4_SludgeDischargeJob {

    @Resource
    private TaskApi taskApi;

    /**
     * 剩余污泥排放电磁阀 job
     */
    @XxlJob("sludgeDischargeStartHandler")
    public void sludgeDischargeStartHandler() throws Exception {
        log.info("sludgeDischargeHandler run");
        Map<Integer, ChannelHandlerContext> contextMap = DeviceDataContainer.CONTEXT_MAP;
        for (Map.Entry<Integer, ChannelHandlerContext> contextEntry : contextMap.entrySet()) {
            taskApi.controSludgeDischarge(contextEntry.getKey(), DeviceDataEnum.OPEN);
        }
        log.info("sludgeDischargeHandler run,excute number:{}", contextMap.size());
    }

}
